#include "stdafx.h"
#include "Utils.h"
using namespace rjksClient;

Utils::Utils(void)
{
}

 String^ Utils::Urlencode(String^ input)
 {
	return System::Uri::EscapeUriString(input);
 }

  String^ Utils::Urldecode(String^ input)
 {
	return System::Uri::UnescapeDataString(input);
 }


 JArray^ Utils::SafeWrapper(JObject^ jo){
	 JArray^ ja=gcnew JArray();
	 if(jo->ToString()->IndexOf("\"data\"")==-1)
		 ja->Add(jo);
	 else
		ja=(JArray^)jo["data"];
	 return ja;
 }

 DateTime Utils::ParseTimeStamp(int timestamp){

    return (gcnew DateTime(1970, 1, 1, 0, 0, 0, 0))->AddSeconds(timestamp).ToLocalTime();
 }
  DateTime Utils::ParseTimeStamp(String^ timestamp){
	  return ParseTimeStamp(int::Parse(timestamp));
  }
 int Utils::GetTimeStamp(){
	  return GetTimeStamp(DateTime::Now);
 }
 
 int Utils::GetTimeStamp(DateTime dt){
	 return (dt.Subtract(DateTime(1970, 1, 1))).TotalSeconds;
 }